package com.itheima.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

@Controller
public class FileUploadController {

    @RequestMapping(value = "/fileupload")
    public String fileupload(MultipartFile[] file, HttpServletRequest request) throws IOException {

        if (file!=null){
            for (MultipartFile f : file) {
                if (!f.isEmpty()){
                    String filename = f.getOriginalFilename();
                    //设置保存路径
                    String realPath = request.getServletContext().getRealPath("/images");
                    f.transferTo(new File(realPath,f.getOriginalFilename()));
                }
            }

        }
    return "page.jsp";

    }










}
